package com.cqie.secondhandtransaction.entity;

import com.baomidou.mybatisplus.annotation.*;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;

import com.cqie.secondhandtransaction.DTO.ProductInfoDTO;
import com.cqie.secondhandtransaction.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;

/**
 * <p>
 * 
 * </p>
 *
 * @author gdy
 * @since 2025-02-10
 */
@Getter
@Setter
@TableName("product_info")
@ApiModel(value = "ProductInfo对象", description = "")
public class ProductInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("商品名称")
    private String productName;

    @ApiModelProperty("二手交易价格")
    private BigDecimal price;

    @ApiModelProperty("商品描述")
    private String description;

    @ApiModelProperty("图片url")
    private String picture;

    @ApiModelProperty("商品类别")
    private Integer typeId;

    @ApiModelProperty("库存")
    private Integer count;

    @ApiModelProperty("状态，S_PUB-发布，DRAFT-草稿,SOLD_OUT-售罄，WAIT_AUDIT-待审核")
    private String status;

    @ApiModelProperty("成色")
    private String productLevel;

    @ApiModelProperty("品牌")
    private String brand;

    @ApiModelProperty("浏览量")
    @TableField(fill = FieldFill.INSERT)
    private Integer viewCount;

    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date createTime;

    @ApiModelProperty("商家")
    private Integer sallorBy;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date updateTime;

    @ApiModelProperty("审核时间")
    @TableField(fill = FieldFill.UPDATE)
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date auditTime;

    @ApiModelProperty("删除人")
    private Integer deleteBy;

    @ApiModelProperty("删除标识")
    @TableLogic
    private Integer isDelete;

    @ApiModelProperty("删除时间")
    @JsonFormat(pattern = DateUtil.DATETIME_FORMAT)
    private Date deleteTime;

    @ApiModelProperty("商家姓名")
    private String sallorName;

    @TableField(exist = false)
    private String typeName;

    @TableField(exist = false, value = "收藏人数")
    private Integer collectionCount;

    @TableField(exist = false, value = "是否收藏")
    private Boolean isCollected = false;

    @TableField(exist = false, value = "商家头像")
    private String sellerAvatar;

    public ProductInfoDTO toProductInfoDTO(){
        ProductInfoDTO dto = new ProductInfoDTO();
        BeanUtils.copyProperties(this, dto);
        return dto;
    }

    public void buildViewCount(){
        //预防新增的时候没有赋值的问题
        if (null == this.viewCount){
            this.viewCount = 0;
        }
        this.viewCount = this.getViewCount() + 1;
    }

}
